<template>
	<view class="register">
		<view class="title">
			手机号注册
		</view>
		<view class="note">
			欢迎注册悠带租账号
		</view>
		
		<view class="input-bg">
			<input @input ='changeMobile' class="uni-input" type="text" name="phone" placeholder="请输入手机号" />
		</view>
	
		<view class="input-bg" style="margin-top:28rpx">
			<input @input='changeCode' class="uni-input2" type="text" name="code" placeholder="请输入验证码" />
			<view  class="get-yzm" @click="smscode">获取验证码</view>
		</view>
		
		<view class="input-bg2">
			<input @input ='changeNickname' class="uni-input" type="text" name="phone" placeholder="请输入用户昵称" />
		</view>
		
		
		<input type="submit" class="submit" value="下一步" @click="nextin">
		<mpopup  ref="mpopup" :isdistance="true"></mpopup>  
		
		
	</view>
</template>

<script>
	var _self;
	import mpopup from '../../components/xuan-popup/xuan-popup.vue';
	export default {
		components:{
			mpopup
		},
		data() {
			return {
				title: 'Hello',
				mobile:'',
				code:'',
				nickname:''
			}
		},
		onLoad() {
			_self = this
		},
		methods: {
			changeMobile(e){
				this.mobile = e.detail.value
			},
			changeCode(e){
				this.code = e.detail.value
				
			},
			changeNickname(e){
				this.nickname = e.detail.value
			},
			smscode(){				
								
				if(!_self.mobile){
					this.$refs.mpopup.open({
						type:'err',
						content:'请填写手机号',
						timeout:2000,
					});
					return false;
				}
				
				uni.request({
				    url: this.websiteUrl+'/userapi.php/Login/smsCode',
					method: 'POST',
				    header: {
				    	'content-type':'application/x-www-form-urlencoded'				  
				    },
					data: {
				        mobile: _self.mobile,
						type: 1
				    },
				    success: function (res) {				    		
							_self.$refs.mpopup.open({
									type:'info',
									content:res.data.msg,
									timeout:2000,
								});							
										
				    }
				});		
			},
			nextin(){		
				if(!_self.mobile){
					this.$refs.mpopup.open({
						type:'err',
						content:'请填写手机号',
						timeout:2000,
					});
					return false;
				}
				if(!_self.code){
					this.$refs.mpopup.open({
						type:'err',
						content:'请输入手机验证码',
						timeout:2000,
					});
					return false;
				}
				if(!_self.nickname){
					this.$refs.mpopup.open({
						type:'err',
						content:'请输入用户昵称',
						timeout:2000,
					});
					return false;
				}
				
				_self = this;
				uni.request({
				    url: this.websiteUrl+'/userapi.php/Login/checkphone',
					method: 'POST',
				    header: {
				    	'content-type':'application/x-www-form-urlencoded'				  
				    },
					data: {
				        mobile: _self.mobile,
						code: _self.code
				    },
				    success: function (res) {
						if(res.data.code == 1){
							uni.navigateTo({
							    url: 'setpwd?mobile='+_self.mobile+'&nickname='+_self.nickname
							});														
						}else{
							_self.$refs.mpopup.open({
									type:'info',
									content:res.data.msg,
									timeout:2000,
							});	
						}								
				    }
				});		
			}		
		}		
	}
</script>

<style>
    .register {
		display: flex;
		flex-direction: column;
		align-items: center;
		background: #E5E5E5;
		height: 1620rpx;
	}
	.title{
		font-size:48rpx;
		line-height:48rpx;
		font-weight: bold;
		margin-top: 126rpx;
	}
	.note{
		font-size:26rpx;
		line-height: 26rpx;
		margin-top: 20rpx;
	}
	.input-bg{
		width:694rpx;
		height:112rpx;
		margin:100rpx 28rpx 28rpx 28rpx;
		background: #FFFFFF;
		border-radius: 60rpx;
	}
	
	.input-bg2{
		width:694rpx;
		height:112rpx;
		margin:28rpx 28rpx 28rpx 28rpx;
		background: #FFFFFF;
		border-radius: 60rpx;
	}
	
	

	.uni-input{
		width:100%;
		height:112rpx;
		line-height: 44rpx;
		font-size: 32rpx;
	    color: #AAAAAA;
		text-align: center;
	}
 .uni-input2{
	     
	    float:left;
		width:65%;
		height:112rpx;
		font-size: 32rpx;
	    color: #AAAAAA;
		text-align: center;
	}

	.get-yzm{
		float:left;
		width:25%;
		height: 112rpx;
		line-height: 112rpx;
		font-size:32rpx;
		color:#FF984C;
	}

	.submit{
		width:300rpx;
		height: 112rpx;
		margin: 60rpx 226rpx;
		background: #FF984C;
		text-align: center;
		color: white;
		line-height: 112px;
		font-size: 32rpx;
		border-radius: 60rpx;
	}
</style>
